//
//  TipCommentContentView.m
//  TipsProject
//
//  Created by Suny on 15/6/20.
//  Copyright (c) 2015年 Suny. All rights reserved.
//

#import "TipCommentContentView.h"
#import "TipCommentDisplayInfo.h"
#import "UIImageView+WebCache.h"
#import "UIView+MGEasyFrame.h"

#define kHeadImageSize 40
@interface TipCommentContentView ()

@property (nonatomic, strong) UIImageView *headImageView;
@property (nonatomic, strong) UILabel     *nameLabel;
@property (nonatomic, strong) UILabel     *timeLabel;
@property (nonatomic, strong) UILabel     *contentLabel;



@end

@implementation TipCommentContentView


- (UIImageView *)headImageView
{
	if (!_headImageView)
	{
		_headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kHeadImageSize, kHeadImageSize)];
		_headImageView.layer.cornerRadius = (CGFloat) (kHeadImageSize/2.0);
		_headImageView.clipsToBounds = YES;
        [self addSubview:_headImageView];
		
	}
	
	return _headImageView;
}

- (UILabel *)nameLabel
{
	if (!_nameLabel)
	{
		_nameLabel = [[UILabel alloc] init];
		_nameLabel.textColor = [UIColor blueColor];
		_nameLabel.backgroundColor = [UIColor clearColor];
        [self addSubview:_nameLabel];
	}
	
	return _nameLabel;
}

- (UILabel *)contentLabel
{
	if (!_contentLabel)
	{
		_contentLabel = [[UILabel alloc] init];
        _contentLabel.width = self.width - kHeadImageSize - 30;
		_contentLabel.textColor = [UIColor blackColor];
		_contentLabel.backgroundColor = [UIColor clearColor];
		_contentLabel.numberOfLines = 0;
        [self addSubview:_contentLabel];
    }
	
	return _contentLabel;
}

- (UILabel *)timeLabel
{
	if (!_timeLabel)
	{
		_timeLabel = [[UILabel alloc] init];
		_timeLabel.textColor = [UIColor lightGrayColor];
		_timeLabel.backgroundColor = [UIColor clearColor];
        [self addSubview:_timeLabel];
	}
	
	return _timeLabel;
}

- (void)updateDisplayInfo:(TipCommentDisplayInfo *)displayInfo
{
	[super updateDisplayInfo:displayInfo];
	self.nameLabel.text = displayInfo.comment.commenterNickName;
    [self.nameLabel sizeToFit];
    self.contentLabel.text = displayInfo.comment.commentContent;
    self.contentLabel.font = displayInfo.contentFont;
    [self.contentLabel sizeToFit];
    self.timeLabel.text = displayInfo.commentCreateTime;
    [self.timeLabel sizeToFit];
}


- (void)layoutSubviews
{
	[super layoutSubviews];
	
	[self.headImageView setQNImageWithURL:[NSURL URLWithString:((TipCommentDisplayInfo *)self.displayInfo).comment.commenterHeadPhoto]
                          placeholderImage:[UIImage imageNamed:kDefaultHeaderImage]];
    self.headImageView.top = 10;
    self.headImageView.left = 10;

    self.nameLabel.top = self.headImageView.top;
    self.nameLabel.left = self.headImageView.right + 10;

    self.timeLabel.right = self.right - 10;
    self.timeLabel.top = self.headImageView.top;

    self.contentLabel.top = self.nameLabel.bottom + 10;
	self.contentLabel.left = self.nameLabel.left;


}


@end
